package com.yaodian100.ec.announcement.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.hibernate.annotations.Formula;
import org.hibernate.annotations.Type;

import com.yaodian100.core.common.entity.BaseEntity;

/**
 * 
 * @author apple.chang
 * 
 */
@Entity
@Table(name = "EC_ANNOUNCEMENT")
public class Announcement extends BaseEntity {

	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 1062958063917311891L;

	/**
	 * 系統流水號
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "seq_ec_announcement")
	@SequenceGenerator(name = "seq_ec_announcement", sequenceName = "SEQ_EC_ANNOUNCEMENT")
	@Column(name = "ID")
	private Long id;

	/**
	 * 公告類別
	 */
	@Column(name = "TYPE", nullable = false)
	private String type;

	/**
	 * 公告標題
	 */
	@Column(name = "SUBJECT", length = 20, nullable = false)
	private String subject;

	/**
	 * 點選公告主旨時的轉址URL
	 */
	@Column(name = "TARGET_URL", length = 100)
	private String targetURL;

	/**
	 * 公告內容
	 */
	@Column(name = "BODY", length = 500)
	private String body;

	/**
	 * 公告上檔日期時間
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "START_DATE", nullable = false)
	private Date startDate;

	/**
	 * 公告下檔日期時間
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "END_DATE", nullable = false)
	private Date endDate;

	/**
	 * 是否刪除(Y/N)
	 */
	@Column(name = "IS_DELETE", length = 1, nullable = false)
	private String isDelete;

	/**
	 * 强化效果(Y/N)
	 */
	@Column(name = "IS_HIGHLIGHT", length = 1, nullable = false)
	private String isHighlight;

	/**
	 * 顯示順序設定(0~6)
	 */
	@Column(name = "SHOW_SEQ")
	private String showSeq;

	/**
	 * 是否設定結束日期
	 */
	@Column(name = "SPECIFY_END_DATE")
	@Type(type = "yes_no")
	private Boolean specifyEndDate = Boolean.valueOf(true);

	/**
	 * 取得中文類別
	 * 
	 * @return
	 */
	@Transient
	public String getTypeName() {
		if ("MYYAODIAN".equals(type)) {
			return "最新快报";
		} else if ("COMMEND_GET_MONEY".equals(type)) {
			return "推荐有钱";
		} else if ("PREFERENTIAL".equals(type)) {
			return "优惠活动";
		} else if ("MIDEND".equals(type)) {
			return "中台公告";
		} else if ("MEMBER_MESSAGE".equals(type)) {
			return "会员讯息";
		} else {
			return "系统公告";
		}
	}

	@Formula(value = "to_number(show_Seq)")
	private Integer showSeqAsNumber;

	/**
	 * 广告代码
	 */
	@Column(name = "AD_WORD", length = 25)
	private String adWord;

	public String getSubject() {
		return subject;
	}

	public void setSubject(String subject) {
		this.subject = subject;
	}

	public String getTargetURL() {
		return targetURL;
	}

	public void setTargetURL(String targetURL) {
		this.targetURL = targetURL;
	}

	public String getBody() {
		return body;
	}

	public void setBody(String body) {
		this.body = body;
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public String getIsDelete() {
		return isDelete;
	}

	public void setIsDelete(String isDelete) {
		this.isDelete = isDelete;
	}

	public Long getId() {
		return id;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getShowSeq() {
		return showSeq;
	}

	public void setShowSeq(String showSeq) {
		this.showSeq = showSeq;
	}

	public String getIsHighlight() {
		return isHighlight;
	}

	public void setIsHighlight(String isHighlight) {
		this.isHighlight = isHighlight;
	}

	public boolean isHighlight() {
		if (this.isHighlight == null) {
			return false;
		}

		if (this.isHighlight.equals("Y")) {
			return true;
		}

		return false;
	}

	public Boolean getSpecifyEndDate() {
		if (this.specifyEndDate == null) {
			return Boolean.valueOf(true);
		}
		return this.specifyEndDate;
	}

	public void setSpecifyEndDate(Boolean specifyEndDate) {
		this.specifyEndDate = specifyEndDate;
	}

	public Integer getShowSeqAsNumber() {
		return this.showSeqAsNumber;
	}

	public void setShowSeqAsNumber(Integer showSeqInNumber) {
		this.showSeqAsNumber = showSeqInNumber;
	}

	public String getAdWord() {
		return adWord;
	}

	public void setAdWord(String adWord) {
		if (null != adWord) {
			this.adWord = adWord;
		} else {
			this.adWord = "";
		}
	}

}